const jwt = require("jsonwebtoken");
const { secret } = require("../config/config");

// 验证Token
exports.authenticateToken = (req, res, next) => {
  console.log("toooooooooooooooooooooooooooooooooken", req.headers["token"]);
  const authHeader = req.headers["token"];
  //   const token = authHeader && authHeader.split(" ")[1];
  const token = authHeader;
  if (token == null) return res.status(401).send("请登录");

  jwt.verify(token, secret, (err, user) => {
    if (err) return res.status(403).send("token过期或者错误");
    req.user = user;
    next();
  });
};
